package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.wemedia.dtos.WmChannelDto;
import com.heima.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Autowired
    private WmChannelService channelService;

    /**
     * 自媒体端,频道列表查询
     */
    @GetMapping("/channels")
    public ResponseResult channelList() {
        return ResponseResult.okResult(channelService.list());
    }

    /**
     * admin端,频道列表分页查询
     */
    @PostMapping("/list")
    public ResponseResult channels(@RequestBody PageRequestDto pageRequestDto) {
        List<WmChannel> wmChannelList = channelService.channelPage(pageRequestDto);
        return ResponseResult.okResult(wmChannelList);
    }

    /**
     * 新增频道
     *
     * @param wmChannelDto 前端参数
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannelDto wmChannelDto) {
        channelService.saveChannel(wmChannelDto);
        return ResponseResult.okResult(null);
    }

    /**
     * 修改频道
     * @param wmChannelDto 前端参数
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannelDto wmChannelDto) {
        channelService.updateChannel(wmChannelDto);
        return ResponseResult.okResult(null);
    }
}
